package com.gwaeron.game;

//omg singleton!

import java.io.File;

import javax.media.Controller;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.format.AudioFormat;

public class MusicPlayer {

	private static MusicPlayer single = new MusicPlayer();

	private Player player;
	private Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
	private Format input2 = new AudioFormat(AudioFormat.MPEG);
	private Format output = new AudioFormat(AudioFormat.LINEAR);

	{
		PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder",
				new Format[] { input1, input2 }, new Format[] { output },
				PlugInManager.CODEC);
	};

	public static MusicPlayer get() {
		return single;
	}

	public void play(String file) {

//		if (player != null) {
//			player.stop();
//		}
//
//		try {
//			player = Manager.createPlayer(new MediaLocator(new File(file)
//					.toURI().toURL()));
//			player.start();
//			System.out.println("Music: playing " + file);
//		} catch (Exception ex) {
//			ex.printStackTrace();
//		}
	}
}